1
|
|
|
var GedcomX = require('../'), |
2
|
|
|
utils = require('../utils'); |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* A description of a source. |
6
|
|
|
* |
7
|
|
|
* @constructor |
8
|
|
|
* @apram {Object} [json] |
9
|
|
|
*/ |
10
|
|
|
var SourceDescription = function(json){ |
11
|
|
|
|
12
|
|
|
// Protect against forgetting the new keyword when calling the constructor |
13
|
|
|
if(!(this instanceof SourceDescription)){ |
14
|
|
|
return new SourceDescription(json); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
// If the given object is already an instance then just return it. DON'T copy it. |
18
|
|
|
if(SourceDescription.isInstance(json)){ |
19
|
|
|
return json; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
this.init(json); |
|
|
|
|
23
|
|
|
}; |
24
|
|
|
|
25
|
|
|
SourceDescription.prototype = Object.create(GedcomX.ExtensibleData.prototype); |
26
|
|
|
|
27
|
|
|
SourceDescription._gedxClass = SourceDescription.prototype._gedxClass = 'GedcomX.SourceDescription'; |
28
|
|
|
|
29
|
|
|
SourceDescription.jsonProps = [ |
30
|
|
|
'resourceType', |
31
|
|
|
'citations', |
32
|
|
|
'mediaType', |
33
|
|
|
'about', |
34
|
|
|
'mediator', |
35
|
|
|
'sources', |
36
|
|
|
'analysis', |
37
|
|
|
'componentOf', |
38
|
|
|
'titles', |
39
|
|
|
'notes', |
40
|
|
|
'attribution', |
41
|
|
|
'rights', |
42
|
|
|
'coverage', |
43
|
|
|
'descriptions', |
44
|
|
|
'identifiers', |
45
|
|
|
'created', |
46
|
|
|
'modified', |
47
|
|
|
'repository' |
48
|
|
|
]; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Check whether the given object is an instance of this class. |
52
|
|
|
* |
53
|
|
|
* @param {Object} obj |
54
|
|
|
* @returns {Boolean} |
55
|
|
|
*/ |
56
|
|
|
SourceDescription.isInstance = function(obj){ |
57
|
|
|
return utils.isInstance(obj, this._gedxClass); |
58
|
|
|
}; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Initialize from JSON |
62
|
|
|
* |
63
|
|
|
* @param {Object} |
|
|
|
|
64
|
|
|
* @return {SourceDescription} this |
65
|
|
|
*/ |
66
|
|
|
SourceDescription.prototype.init = function(json){ |
67
|
|
|
|
68
|
|
|
GedcomX.ExtensibleData.prototype.init.call(this, json); |
69
|
|
|
|
70
|
|
|
if(json){ |
71
|
|
|
this.setResourceType(json.resourceType); |
72
|
|
|
this.setCitations(json.citations); |
73
|
|
|
this.setMediaType(json.mediaType); |
74
|
|
|
this.setAbout(json.about); |
75
|
|
|
this.setMediator(json.mediator); |
76
|
|
|
this.setSources(json.sources); |
77
|
|
|
this.setAnalysis(json.analysis); |
78
|
|
|
this.setComponentOf(json.componentOf); |
79
|
|
|
this.setTitles(json.titles); |
80
|
|
|
this.setNotes(json.notes); |
81
|
|
|
this.setAttribution(json.attribution); |
82
|
|
|
this.setRights(json.rights); |
83
|
|
|
this.setCoverage(json.coverage); |
84
|
|
|
this.setDescriptions(json.descriptions); |
85
|
|
|
this.setIdentifiers(json.identifiers); |
86
|
|
|
this.setCreated(json.created); |
87
|
|
|
this.setModified(json.modified); |
88
|
|
|
this.setRepository(json.repository); |
89
|
|
|
} |
90
|
|
|
return this; |
91
|
|
|
}; |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Get the resource type |
95
|
|
|
* |
96
|
|
|
* @returns {String} |
97
|
|
|
*/ |
98
|
|
|
SourceDescription.prototype.getResourceType = function(){ |
99
|
|
|
return this.resourceType; |
100
|
|
|
}; |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Set the resource type |
104
|
|
|
* |
105
|
|
|
* @param {String} resourceType |
106
|
|
|
* @returns {SourceDescription} |
107
|
|
|
*/ |
108
|
|
|
SourceDescription.prototype.setResourceType = function(resourceType){ |
109
|
|
|
this.resourceType = resourceType; |
110
|
|
|
return this; |
111
|
|
|
}; |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Get the citations |
115
|
|
|
* |
116
|
|
|
* @returns {SourceCitation[]} |
117
|
|
|
*/ |
118
|
|
|
SourceDescription.prototype.getCitations = function(){ |
119
|
|
|
return this.citations || []; |
120
|
|
|
}; |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Set the citations |
124
|
|
|
* |
125
|
|
|
* @param {SourceCitation[]|Object[]} citations |
126
|
|
|
* @returns {SourceDescription} |
127
|
|
|
*/ |
128
|
|
|
SourceDescription.prototype.setCitations = function(citations){ |
129
|
|
|
return this._setArray(citations, 'citations', 'addCitation'); |
130
|
|
|
}; |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Add a citation |
134
|
|
|
* |
135
|
|
|
* @param {SourceCitation|Object} citation |
136
|
|
|
* @returns {SourceDescription} |
137
|
|
|
*/ |
138
|
|
|
SourceDescription.prototype.addCitation = function(citation){ |
139
|
|
|
return this._arrayPush(citation, 'citations', GedcomX.SourceCitation); |
140
|
|
|
}; |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Get the media type |
144
|
|
|
* |
145
|
|
|
* @return {String} |
146
|
|
|
*/ |
147
|
|
|
SourceDescription.prototype.getMediaType = function(){ |
148
|
|
|
return this.mediaType; |
149
|
|
|
}; |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Set the media type |
153
|
|
|
* |
154
|
|
|
* @param {String} mediaType |
155
|
|
|
* @returns {SourceDescription} |
156
|
|
|
*/ |
157
|
|
|
SourceDescription.prototype.setMediaType = function(mediaType){ |
158
|
|
|
this.mediaType = mediaType; |
159
|
|
|
return this; |
160
|
|
|
}; |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Get the about property |
164
|
|
|
* |
165
|
|
|
* @returns {String} |
166
|
|
|
*/ |
167
|
|
|
SourceDescription.prototype.getAbout = function(){ |
168
|
|
|
return this.about; |
169
|
|
|
}; |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* Set the about property |
173
|
|
|
* |
174
|
|
|
* @param {String} about |
175
|
|
|
* @returns {SourceDescription} |
176
|
|
|
*/ |
177
|
|
|
SourceDescription.prototype.setAbout = function(about){ |
178
|
|
|
this.about = about; |
179
|
|
|
return this; |
180
|
|
|
}; |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* Get the mediator |
184
|
|
|
* |
185
|
|
|
* @returns {ResourceReference} |
186
|
|
|
*/ |
187
|
|
|
SourceDescription.prototype.getMediator = function(){ |
188
|
|
|
return this.mediator; |
189
|
|
|
}; |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* Set the mediator |
193
|
|
|
* |
194
|
|
|
* @param {ResourceReference} mediator |
195
|
|
|
* @returns {SourceDescription} |
196
|
|
|
*/ |
197
|
|
|
SourceDescription.prototype.setMediator = function(mediator){ |
198
|
|
|
if(mediator){ |
199
|
|
|
this.mediator = GedcomX.ResourceReference(mediator); |
200
|
|
|
} |
201
|
|
|
return this; |
202
|
|
|
}; |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* Get sources |
206
|
|
|
* |
207
|
|
|
* @returns {SourceReference[]} |
208
|
|
|
*/ |
209
|
|
|
SourceDescription.prototype.getSources = function(){ |
210
|
|
|
return this.sources || []; |
211
|
|
|
}; |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* Set the sources |
215
|
|
|
* |
216
|
|
|
* @param {SourceReference[]|Object[]} sources |
217
|
|
|
* @returns {SourceDescription} |
218
|
|
|
*/ |
219
|
|
|
SourceDescription.prototype.setSources = function(sources){ |
220
|
|
|
return this._setArray(sources, 'sources', 'addSource'); |
221
|
|
|
}; |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* Add a source |
225
|
|
|
* |
226
|
|
|
* @param {SourceReference|Object} |
|
|
|
|
227
|
|
|
* @returns {SourceDescription} |
228
|
|
|
*/ |
229
|
|
|
SourceDescription.prototype.addSource = function(source){ |
230
|
|
|
return this._arrayPush(source, 'sources', GedcomX.SourceReference); |
231
|
|
|
}; |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* Get the analysis |
235
|
|
|
* |
236
|
|
|
* @return {ResourceReference} |
237
|
|
|
*/ |
238
|
|
|
SourceDescription.prototype.getAnalysis = function(){ |
239
|
|
|
return this.analysis; |
240
|
|
|
}; |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* Set the analysis |
244
|
|
|
* |
245
|
|
|
* @param {ResourceReference|Object} analysis |
246
|
|
|
* @return {SourceDescription} |
247
|
|
|
*/ |
248
|
|
|
SourceDescription.prototype.setAnalysis = function(analysis){ |
249
|
|
|
if(analysis){ |
250
|
|
|
this.analysis = GedcomX.ResourceReference(analysis); |
251
|
|
|
} |
252
|
|
|
return this; |
253
|
|
|
}; |
254
|
|
|
|
255
|
|
|
/** |
256
|
|
|
* Get the componentOf property |
257
|
|
|
* |
258
|
|
|
* @return {SourceReference} |
259
|
|
|
*/ |
260
|
|
|
SourceDescription.prototype.getComponentOf = function(){ |
261
|
|
|
return this.componentOf; |
262
|
|
|
}; |
263
|
|
|
|
264
|
|
|
/** |
265
|
|
|
* Set the componentOf property |
266
|
|
|
* |
267
|
|
|
* @param {SourceReference} componentOf |
268
|
|
|
*/ |
269
|
|
|
SourceDescription.prototype.setComponentOf = function(componentOf){ |
270
|
|
|
if(componentOf){ |
271
|
|
|
this.componentOf = GedcomX.SourceReference(componentOf); |
272
|
|
|
} |
273
|
|
|
return this; |
274
|
|
|
}; |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* Get titles |
278
|
|
|
* |
279
|
|
|
* @returns {TextValue[]} |
280
|
|
|
*/ |
281
|
|
|
SourceDescription.prototype.getTitles = function(){ |
282
|
|
|
return this.titles || []; |
283
|
|
|
}; |
284
|
|
|
|
285
|
|
|
/** |
286
|
|
|
* Set the titles |
287
|
|
|
* |
288
|
|
|
* @param {TextValue[]|Object[]} titles |
289
|
|
|
* @returns {SourceDescription} |
290
|
|
|
*/ |
291
|
|
|
SourceDescription.prototype.setTitles = function(titles){ |
292
|
|
|
return this._setArray(titles, 'titles', 'addTitle'); |
293
|
|
|
}; |
294
|
|
|
|
295
|
|
|
/** |
296
|
|
|
* Add a title |
297
|
|
|
* |
298
|
|
|
* @param {TextValue|Object} |
|
|
|
|
299
|
|
|
* @returns {SourceDescription} |
300
|
|
|
*/ |
301
|
|
|
SourceDescription.prototype.addTitle = function(title){ |
302
|
|
|
return this._arrayPush(title, 'titles', GedcomX.TextValue); |
303
|
|
|
}; |
304
|
|
|
|
305
|
|
|
/** |
306
|
|
|
* Get notes |
307
|
|
|
* |
308
|
|
|
* @returns {Note[]} |
309
|
|
|
*/ |
310
|
|
|
SourceDescription.prototype.getNotes = function(){ |
311
|
|
|
return this.notes || []; |
312
|
|
|
}; |
313
|
|
|
|
314
|
|
|
/** |
315
|
|
|
* Set the notes |
316
|
|
|
* |
317
|
|
|
* @param {Note[]|Object[]} notes |
318
|
|
|
* @returns {SourceDescription} |
319
|
|
|
*/ |
320
|
|
|
SourceDescription.prototype.setNotes = function(notes){ |
321
|
|
|
return this._setArray(notes, 'notes', 'addNote'); |
322
|
|
|
}; |
323
|
|
|
|
324
|
|
|
/** |
325
|
|
|
* Add a source |
326
|
|
|
* |
327
|
|
|
* @param {Note|Object} note |
328
|
|
|
* @returns {SourceDescription} |
329
|
|
|
*/ |
330
|
|
|
SourceDescription.prototype.addNote = function(note){ |
331
|
|
|
return this._arrayPush(note, 'notes', GedcomX.Note); |
332
|
|
|
}; |
333
|
|
|
|
334
|
|
|
/** |
335
|
|
|
* Get the attribution |
336
|
|
|
* |
337
|
|
|
* @returns {Attribution} |
338
|
|
|
*/ |
339
|
|
|
SourceDescription.prototype.getAttribution = function(){ |
340
|
|
|
return this.attribution; |
341
|
|
|
}; |
342
|
|
|
|
343
|
|
|
/** |
344
|
|
|
* Set the attribution |
345
|
|
|
* |
346
|
|
|
* @param {Attribution|Object} attribution |
347
|
|
|
* @returns {SourceDescription} |
348
|
|
|
*/ |
349
|
|
|
SourceDescription.prototype.setAttribution = function(attribution){ |
350
|
|
|
if(attribution){ |
351
|
|
|
this.attribution = GedcomX.Attribution(attribution); |
352
|
|
|
} |
353
|
|
|
return this; |
354
|
|
|
}; |
355
|
|
|
|
356
|
|
|
/** |
357
|
|
|
* Get the rights |
358
|
|
|
* |
359
|
|
|
* @returns {ResourceReference[]} |
360
|
|
|
*/ |
361
|
|
|
SourceDescription.prototype.getRights = function(){ |
362
|
|
|
return this.rights || []; |
363
|
|
|
}; |
364
|
|
|
|
365
|
|
|
/** |
366
|
|
|
* Set the rights |
367
|
|
|
* |
368
|
|
|
* @param {ResourceReference[]|Object[]} rights |
369
|
|
|
* @returns {SourceDescription} |
370
|
|
|
*/ |
371
|
|
|
SourceDescription.prototype.setRights = function(rights){ |
372
|
|
|
return this._setArray(rights, 'rights', 'addRight'); |
373
|
|
|
}; |
374
|
|
|
|
375
|
|
|
/** |
376
|
|
|
* Add a source |
377
|
|
|
* |
378
|
|
|
* @param {ResourceReference|Object} right |
379
|
|
|
* @returns {SourceDescription} |
380
|
|
|
*/ |
381
|
|
|
SourceDescription.prototype.addRight = function(right){ |
382
|
|
|
return this._arrayPush(right, 'rights', GedcomX.ResourceReference); |
383
|
|
|
}; |
384
|
|
|
|
385
|
|
|
/** |
386
|
|
|
* Get the coverage |
387
|
|
|
* |
388
|
|
|
* @returns {Coverage} |
389
|
|
|
*/ |
390
|
|
|
SourceDescription.prototype.getCoverage = function(){ |
391
|
|
|
return this.coverage; |
392
|
|
|
}; |
393
|
|
|
|
394
|
|
|
/** |
395
|
|
|
* Set the coverage |
396
|
|
|
* |
397
|
|
|
* @param {Coverage|Object} coverage |
398
|
|
|
* @returns {SourceDescription} |
399
|
|
|
*/ |
400
|
|
|
SourceDescription.prototype.setCoverage = function(coverage){ |
401
|
|
|
if(coverage){ |
402
|
|
|
this.coverage = GedcomX.Coverage(coverage); |
403
|
|
|
} |
404
|
|
|
return this; |
405
|
|
|
}; |
406
|
|
|
|
407
|
|
|
/** |
408
|
|
|
* Get the descriptions |
409
|
|
|
* |
410
|
|
|
* @returns {TextValue[]} |
411
|
|
|
*/ |
412
|
|
|
SourceDescription.prototype.getDescriptions = function(){ |
413
|
|
|
return this.descriptions || []; |
414
|
|
|
}; |
415
|
|
|
|
416
|
|
|
/** |
417
|
|
|
* Set the descriptions |
418
|
|
|
* |
419
|
|
|
* @param {TextValue[]|Object[]} descriptions |
420
|
|
|
* @returns {SourceDescription} |
421
|
|
|
*/ |
422
|
|
|
SourceDescription.prototype.setDescriptions = function(descriptions){ |
423
|
|
|
return this._setArray(descriptions, 'descriptions', 'addDescription'); |
424
|
|
|
}; |
425
|
|
|
|
426
|
|
|
/** |
427
|
|
|
* Add a description |
428
|
|
|
* |
429
|
|
|
* @param {TextValue|Object} |
|
|
|
|
430
|
|
|
* @returns {SourceDescription} |
431
|
|
|
*/ |
432
|
|
|
SourceDescription.prototype.addDescription = function(description){ |
433
|
|
|
return this._arrayPush(description, 'descriptions', GedcomX.TextValue); |
434
|
|
|
}; |
435
|
|
|
|
436
|
|
|
/** |
437
|
|
|
* Get the identifiers |
438
|
|
|
* |
439
|
|
|
* @returns {Identifiers} |
440
|
|
|
*/ |
441
|
|
|
SourceDescription.prototype.getIdentifiers = function(){ |
442
|
|
|
return this.identifiers; |
443
|
|
|
}; |
444
|
|
|
|
445
|
|
|
/** |
446
|
|
|
* Set the identifiers |
447
|
|
|
* |
448
|
|
|
* @param {Identifiers} identifiers |
449
|
|
|
* @returns {SourceDescription} |
450
|
|
|
*/ |
451
|
|
|
SourceDescription.prototype.setIdentifiers = function(identifiers){ |
452
|
|
|
if(identifiers){ |
453
|
|
|
this.identifiers = GedcomX.Identifiers(identifiers); |
454
|
|
|
} |
455
|
|
|
return this; |
456
|
|
|
}; |
457
|
|
|
|
458
|
|
|
/** |
459
|
|
|
* Get the created timestamp |
460
|
|
|
* |
461
|
|
|
* @returns {Integer} |
462
|
|
|
*/ |
463
|
|
|
SourceDescription.prototype.getCreated = function(){ |
464
|
|
|
return this.created; |
465
|
|
|
}; |
466
|
|
|
|
467
|
|
|
/** |
468
|
|
|
* Set the created timestamp |
469
|
|
|
* |
470
|
|
|
* @param {Integer} created |
471
|
|
|
* @returns {SourceDescription} |
472
|
|
|
*/ |
473
|
|
|
SourceDescription.prototype.setCreated = function(created){ |
474
|
|
|
this.created = created; |
475
|
|
|
return this; |
476
|
|
|
}; |
477
|
|
|
|
478
|
|
|
/** |
479
|
|
|
* Get the modified timestamp |
480
|
|
|
* |
481
|
|
|
* @returns {Integer} |
482
|
|
|
*/ |
483
|
|
|
SourceDescription.prototype.getModified = function(){ |
484
|
|
|
return this.modified; |
485
|
|
|
}; |
486
|
|
|
|
487
|
|
|
/** |
488
|
|
|
* Set the modified timestamp |
489
|
|
|
* |
490
|
|
|
* @param {Integer} modified |
491
|
|
|
* @returns {SourceDescription} |
492
|
|
|
*/ |
493
|
|
|
SourceDescription.prototype.setModified = function(modified){ |
494
|
|
|
this.modified = modified; |
495
|
|
|
return this; |
496
|
|
|
}; |
497
|
|
|
|
498
|
|
|
/** |
499
|
|
|
* Get the repository |
500
|
|
|
* |
501
|
|
|
* @returns {ResourceReference} |
502
|
|
|
*/ |
503
|
|
|
SourceDescription.prototype.getRepository = function(){ |
504
|
|
|
return this.repository; |
505
|
|
|
}; |
506
|
|
|
|
507
|
|
|
/** |
508
|
|
|
* Set the repository |
509
|
|
|
* |
510
|
|
|
* @param {ResourceReference} repository |
511
|
|
|
* @returns {SourceDescription} |
512
|
|
|
*/ |
513
|
|
|
SourceDescription.prototype.setRepository = function(repository){ |
514
|
|
|
if(repository){ |
515
|
|
|
this.repository = GedcomX.ResourceReference(repository); |
516
|
|
|
} |
517
|
|
|
return this; |
518
|
|
|
}; |
519
|
|
|
|
520
|
|
|
/** |
521
|
|
|
* Export the object as JSON |
522
|
|
|
* |
523
|
|
|
* @return {Object} JSON object |
524
|
|
|
*/ |
525
|
|
|
SourceDescription.prototype.toJSON = function(){ |
526
|
|
|
return this._toJSON(GedcomX.ExtensibleData, SourceDescription.jsonProps); |
527
|
|
|
}; |
528
|
|
|
|
529
|
|
|
module.exports = SourceDescription; |